package com.zijin.controller.user;


import com.zijin.PageQureyDTO;
import com.zijin.annotation.Authority;
import com.zijin.dto.user.UserRoleDTO;
import com.zijin.result.PageResult;
import com.zijin.result.Result;
import com.zijin.service.user.IUserRoleService;
import com.zijin.vo.user.UserRoleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户和角色关联表 前端控制器
 * </p>
 *
 * @author JWei Xu
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/base/userRole")
public class UserRoleController {


    @Resource
    @Lazy
    IUserRoleService userRoleService;

    /** 增 */
    @PostMapping("/addOne")
    @ApiOperation("新增")
    @Authority("admin")
    public Result<Boolean> addOne(@RequestBody @Validated UserRoleDTO dto){
        return Result.success(userRoleService.addOne(dto));
    }

    /** 删 */
    @DeleteMapping("/delOne/{id}")
    @ApiOperation("删除")
    @Authority("admin")
    public Result<Boolean> delOne(@PathVariable Long id){
        return Result.success(userRoleService.delOne(id));
    }

    /** 改 ,没有改，删除后重新添加*/

    /** 查 */
    @GetMapping("/getOne/{id}")
    @ApiOperation("查找一个")
    @Authority("admin")
    public Result<UserRoleVo> getOne(@PathVariable Long id){
        //不能ById需要连表
        return Result.success(userRoleService.getUserRole(id));
    }
    
    /** 查 */
    @GetMapping("/getPage")
    @ApiOperation("查找page")
    @Authority("admin")
    public Result<PageResult> getPage(PageQureyDTO dto){
        //不能ById需要连表
        return Result.success(userRoleService.getPage(dto));
    }





}
